package com.mugu.yunying;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mugu.common.annotation.Log;
import com.mugu.common.core.controller.BaseController;
import com.mugu.common.core.domain.AjaxResult;
import com.mugu.common.enums.BusinessType;
import com.mugu.yunying.domain.PhoneCode;
import com.mugu.yunying.service.IPhoneCodeService;
import com.mugu.common.utils.poi.ExcelUtil;
import com.mugu.common.core.page.TableDataInfo;

/**
 * 手机验证码Controller
 * 
 * @author ruoyi
 * @date 2021-03-27
 */
@RestController
@RequestMapping("/yunying/code")
public class PhoneCodeController extends BaseController
{
    @Autowired
    private IPhoneCodeService phoneCodeService;

    /**
     * 查询手机验证码列表
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:list')")
    @GetMapping("/list")
    public TableDataInfo list(PhoneCode phoneCode)
    {
        startPage();
        List<PhoneCode> list = phoneCodeService.selectPhoneCodeList(phoneCode);
        return getDataTable(list);
    }

    /**
     * 导出手机验证码列表
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:export')")
    @Log(title = "手机验证码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PhoneCode phoneCode)
    {
        List<PhoneCode> list = phoneCodeService.selectPhoneCodeList(phoneCode);
        ExcelUtil<PhoneCode> util = new ExcelUtil<PhoneCode>(PhoneCode.class);
        return util.exportExcel(list, "code");
    }

    /**
     * 获取手机验证码详细信息
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(phoneCodeService.selectPhoneCodeById(id));
    }

    /**
     * 新增手机验证码
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:add')")
    @Log(title = "手机验证码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PhoneCode phoneCode)
    {
        return toAjax(phoneCodeService.insertPhoneCode(phoneCode));
    }

    /**
     * 修改手机验证码
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:edit')")
    @Log(title = "手机验证码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PhoneCode phoneCode)
    {
        return toAjax(phoneCodeService.updatePhoneCode(phoneCode));
    }

    /**
     * 删除手机验证码
     */
    @PreAuthorize("@ss.hasPermi('yunying:code:remove')")
    @Log(title = "手机验证码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(phoneCodeService.deletePhoneCodeByIds(ids));
    }
}
